package com.linpq.road.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.linpq.common.annotation.Log;
import com.linpq.common.enums.BusinessType;
import com.linpq.road.domain.RdTrafficInfo;
import com.linpq.road.service.RdTrafficInfoService;
import com.linpq.common.core.controller.BaseController;
import com.linpq.common.core.domain.AjaxResult;
import com.linpq.common.utils.poi.ExcelUtil;
import com.linpq.common.core.page.TableDataInfo;

/**
 * 交通信息Controller
 *
 * @author linpq
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/road/traffic_info")
public class RdTrafficInfoController extends BaseController {
    private String prefix = "road/traffic_info";

    @Autowired
    private RdTrafficInfoService rdTrafficInfoService;

    @RequiresPermissions("road:traffic_info:view")
    @GetMapping()
    public String traffic_info() {
        return prefix + "/traffic_info";
    }

    /**
     * 查询交通信息列表
     */
    @RequiresPermissions("road:traffic_info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RdTrafficInfo rdTrafficInfo) {
        startPage();
        List<RdTrafficInfo> list = rdTrafficInfoService.selectRdTrafficInfoList(rdTrafficInfo);
        return getDataTable(list);
    }

    /**
     * 导出交通信息列表
     */
    @RequiresPermissions("road:traffic_info:export")
    @Log(title = "交通信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RdTrafficInfo rdTrafficInfo) {
        List<RdTrafficInfo> list = rdTrafficInfoService.selectRdTrafficInfoList(rdTrafficInfo);
        ExcelUtil<RdTrafficInfo> util = new ExcelUtil<RdTrafficInfo>(RdTrafficInfo. class);
        return util.exportExcel(list, "traffic_info");
    }

    /**
     * 新增交通信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存交通信息
     */
    @RequiresPermissions("road:traffic_info:add")
    @Log(title = "交通信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RdTrafficInfo rdTrafficInfo) {
        return toAjax(rdTrafficInfoService.insertRdTrafficInfo(rdTrafficInfo));
    }

    /**
     * 修改交通信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        RdTrafficInfo rdTrafficInfo =rdTrafficInfoService.selectRdTrafficInfoById(id);
        mmap.put("rdTrafficInfo", rdTrafficInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存交通信息
     */
    @RequiresPermissions("road:traffic_info:edit")
    @Log(title = "交通信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RdTrafficInfo rdTrafficInfo) {
        return toAjax(rdTrafficInfoService.updateRdTrafficInfo(rdTrafficInfo));
    }

    /**
     * 删除交通信息
     */
    @RequiresPermissions("road:traffic_info:remove")
    @Log(title = "交通信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(rdTrafficInfoService.deleteRdTrafficInfoByIds(ids));
    }
}
